<template>
  <div class="MdEdit">
    <Editor
      :locale="zh_Hans"
      :mode="mode"
      :plugins="plugins"
      :value="value"
      style="min-height: 400px; min-width: 1100px; width: 100%; height: 50vh"
      @change="handleChange"
    />
  </div>
</template>

<script lang="ts" setup>
import gfm from "@bytemd/plugin-gfm";
import highlight from "@bytemd/plugin-highlight";
import mermaid from "@bytemd/plugin-mermaid";
import { Editor } from "@bytemd/vue-next";
import "bytemd/dist/index.css";
import "juejin-markdown-themes/dist/juejin.css";
import "highlight.js/styles/vs.css";
import zh_Hans from "bytemd/locales/zh_Hans.json";
import { defineProps, withDefaults } from "vue";

// 定义组件类型
interface Props {
  value: string;
  mode?: string;
  handleChange: (v: string) => void;
}

// 使用defineProps接收传递参数
const props = withDefaults(defineProps<Props>(), {
  value: () => "",
  mode: () => "split",
  handleChange: (v: string) => {
    console.log(v);
  },
});

const plugins = [
  gfm(),
  // Add more plugins here
  highlight(),
  mermaid(),
];
</script>

<style>
// 将scoped去掉即可
.bytemd-toolbar-icon .bytemd-tippy .bytemd-tippy-right :last-child {
  display: none;
}
.bytemd-toolbar-right .bytemd-toolbar-icon:last-child {
  display: none;
}
.bytemd bytemd-split {
  height: 50vh;
}
.MdEdit {
  width: 100%;
}
</style>
